package com.lsl.factory_kit.factory;

import com.lsl.factory_kit.builder.Builder;
import com.lsl.factory_kit.weapon.Weapon;
import com.lsl.factory_kit.weapontype.WeaponType;

import java.util.HashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author Zed
 * @description
 * @date 2023/1/8 21:34
 */
public interface WeaponFactory {


    Weapon create(WeaponType name);


    static WeaponFactory factory(Consumer<Builder> consumer) {
        HashMap<WeaponType, Supplier<Weapon>> map = new HashMap<>();
        consumer.accept(map::put);
        return name -> map.get(name).get();
    }
}
